<?php
/**
 * Created by PhpStorm.
 * User: dev
 * Date: 12/11/14
 * Time: 5:16 PM
 */
class Member_Message_Controller extends Base_Controller
{

    public $restful = true;

    public function __construct()
    {
        parent::__construct();
        //--Your Code --//
        $this->theme->set_theme("default");
        $this->theme->set_layout("member");


    }

    public function get_index(){
        $user = Auth::user();
        $data['title'] = 'Messages';

        //--Get all Business Messages --//
        //$d = Users::find($user->id)->post()->leftJoin('comments', 'comments.post_id', '=', 'post.id')->get();
        $sql = "SELECT C.* from comments C
			INNER JOIN post P on P.id = C.post_id
			and P.users_id = $user->id order by(C.id) DESC limit 0,25";

        $data['comments'] = DB::query($sql);
        /*-- META DATA */
        $this->theme->title($data['title'].' - '.Settings::get('en','site_title'));
        /*-- BREADCRUMB */

        Breadcrumb::addbreadcrumb('Home', URL::base());
        Breadcrumb::addbreadcrumb('Dashboard', URL::base().'/member');
        Breadcrumb::addbreadcrumb($data['title'], URL::base());
        Breadcrumb::setSeparator('&raquo;');
        $data['breadcrumb'] = Breadcrumb::generate();
        return $this->theme->render('member::message', $data);
    }

    public function get_delete($id){
        Comments::find($id)->delete();
        return Redirect::back();
    }
}